package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	pb "user_service/proto"
)

var userClient pb.UserClient
var conn *grpc.ClientConn

func Init() {
	var err error
	conn, err = grpc.Dial("192.168.90.238:56630", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		panic(err)
	}
	userClient = pb.NewUserClient(conn)
}

func main() {
	Init()
	//TestGetUserById()
	TestCreateUser()
	conn.Close()
}

func TestGetUserById() {
	response, err := userClient.GetUserById(context.Background(), &pb.IdRequest{Id: "66d561309106b7f1e63adec9"})
	if err != nil {
		panic(err)
	}
	fmt.Printf("姓名：%s 手机号：%s 密码：%s", response.Name, response.Email, response.Password)
}

func TestCreateUser() {
	response, err := userClient.CreateUser(context.Background(), &pb.CreateUserInfoRequest{Mobile: "13800138000", Name: "alex", Email: "1390714", Password: "123456"})
	if err != nil {
		panic(err)
	}
	fmt.Printf("姓名：%s 手机号：%s 密码：%s 名字： %s", response.Name, response.Email, response.Password, response.Name)
}
